package com.andatsoft.laisim.activity.setting;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andatsoft.laisim.R;
import com.andatsoft.laisim.activity.BaseActivity;
import com.andatsoft.laisim.dialog.ChangelogDialog;
import com.andatsoft.laisim.theme.ThemeManager;

public class AboutActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting_about);
		((TextView) findViewById(R.id.tv_setting_about_version))
				.setText(getString(R.string.setting_about_version) + " 2.1.2.2");
		((TextView) findViewById(R.id.tv_setting_about_theme_name))
				.setText(getString(R.string.setting_about_theme_name) + " "
						+ ThemeManager.getSelectedTheme().getThemeName());
		((TextView) findViewById(R.id.tv_setting_about_theme_author))
				.setText(getString(R.string.setting_about_theme_author) + " "
						+ ThemeManager.getSelectedTheme().getAuthorName());
		((TextView) findViewById(R.id.tv_setting_about_theme_info))
				.setText(getString(R.string.setting_about_theme_info) + " "
						+ ThemeManager.getSelectedTheme().getAuthorInfo());

		((TextView) findViewById(R.id.tv_setting_about_skin_name))
				.setText(getString(R.string.setting_about_skin_name) + " "
						+ ThemeManager.getSelectedSkin().getSkinName());
		((TextView) findViewById(R.id.tv_setting_about_skin_author))
				.setText(getString(R.string.setting_about_skin_author) + " "
						+ ThemeManager.getSelectedSkin().getAuthorName());
		((TextView) findViewById(R.id.tv_setting_about_skin_info))
				.setText(getString(R.string.setting_about_skin_info) + " "
						+ ThemeManager.getSelectedSkin().getAuthorInfo());
		((LinearLayout) findViewById(R.id.layout_setting_about_credit))
				.setOnTouchListener(new OnTouchListener() {

					@Override
					public boolean onTouch(View v, MotionEvent event) {
						switch (event.getAction()) {
						case MotionEvent.ACTION_DOWN:
							v.setBackgroundColor(0x50ffffff);
							return true;
						case MotionEvent.ACTION_UP:
							v.setBackgroundColor(0xff000000);
							startActivity(new Intent(AboutActivity.this,
									CreditActivity.class));
							return true;
						case MotionEvent.ACTION_CANCEL:
							v.setBackgroundColor(0xff000000);
							return true;
						}

						return false;
					}
				});
		((LinearLayout) findViewById(R.id.layout_setting_about_change_log))
				.setOnTouchListener(new OnTouchListener() {

					@Override
					public boolean onTouch(View v, MotionEvent event) {
						switch (event.getAction()) {
						case MotionEvent.ACTION_DOWN:
							v.setBackgroundColor(0x50ffffff);
							return true;
						case MotionEvent.ACTION_UP:
							v.setBackgroundColor(0xff000000);
							startActivity(new Intent(AboutActivity.this,
									ChangelogDialog.class));
							return true;
						case MotionEvent.ACTION_CANCEL:
							v.setBackgroundColor(0xff000000);
							return true;
						}
						return false;
					}
				});
		((LinearLayout) findViewById(R.id.layout_setting_about_andatsoft_product))
				.setOnTouchListener(new OnTouchListener() {

					@Override
					public boolean onTouch(View v, MotionEvent event) {
						switch (event.getAction()) {
						case MotionEvent.ACTION_DOWN:
							v.setBackgroundColor(0x50ffffff);
							return true;
						case MotionEvent.ACTION_UP:
							v.setBackgroundColor(0xff000000);
							try {
								startActivity(new Intent(
										Intent.ACTION_VIEW,
										Uri.parse("market://search?q=Andatsoft")));
							} catch (android.content.ActivityNotFoundException anfe) {
								startActivity(new Intent(
										Intent.ACTION_VIEW,
										Uri.parse("http://play.google.com/store/apps/search?q=Andatsoft")));
							}
							return true;
						case MotionEvent.ACTION_CANCEL:
							v.setBackgroundColor(0xff000000);
							return true;
						}
						return false;
					}
				});
	}
}
